/**
 * Copyright (c) 2019 EOVA.CN. All rights reserved.
 * 
 * Licensed to: 珠海易立方软件有限公司(414693478@qq.com)
 * Licensed under the EPPL license: http://eova.cn/eppl.txt
 * Software copyright registration number:2018SR1012969
 * For authorization, please contact: admin@eova.cn
 */
package com.eova.core.admin;

import com.eova.common.Easy;
import com.eova.common.base.BaseController;
import com.eova.common.utils.xx;
import com.eova.config.EovaConfig;
import com.eova.model.User;
import com.jfinal.aop.Before;

/**
 * EOVA超级管理功能
 * @author Jieven
 *
 */
@Before(AdminInterceptor.class)
public class AdminController extends BaseController {

	/**
	 * 升级控制台
	 */
	public void upgrade() {
		String isUpgrade = EovaConfig.getProps().get("isUpgrade");
		if (xx.isEmpty(isUpgrade) || !isUpgrade.equals("true")) {
			renderText("未开启升级模式，请启动配置 isUpgrade = true, 用完之后立马关掉,后果自负!");
			return;
		}

		render("/eova/admin/upgrade.html");
	}

	// 超级切换 
	public void su() {
		render("/eova/admin/su.html");
	}

	public void doSu() {
		int uid = getParaToInt(0);
		int rid = getParaToInt(1);

		User user = getUser();
		user.set("id", uid);
		user.put("su_rid", rid);
		user.put("org_id", getParaToInt(2, 0));
		user.set("name", get("name"));
		updateUser(user);

		renderJson(Easy.sucess());
	}
	//	public void init() {
	//		render("/eova/admin/init.html");
	//	}
	//	public void doInit() {
	//		String ip = getPara("ip");
	//		String port = getPara("port");
	//		String userName = getPara("userName");
	//		String password = getPara("password");
	//
	//		keepPara(ip);
	//		keepPara(port);
	//		keepPara(userName);
	//		keepPara(password);
	//
	//		String local_url = MessageFormat.format("jdbc:mysql://{0}:{1}/web?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull", ip, port);
	//		// String local_user = userName;
	//		// String local_pwd = password;
	//
	//		// String local_eova_url = MessageFormat.format("jdbc:mysql://{0}:{1}/eova?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull", ip, port);
	//		// String local_eova_user = userName;
	//		// String local_eova_pwd = password;
	//
	//		// 自动生成JDBC配置 to eova.config
	//		String msg = JdbcUtil.initConnection(local_url, userName, password);
	//		if (msg != null) {
	//
	//			if (msg.startsWith("Communications link failure")) {
	//				msg = "无法连接数据库，请检查IP:Port";
	//			} else if (msg.startsWith("Access denied for user")) {
	//				msg = "用户无权限访问，请检查用户名和密码";
	//			}
	//
	//			setAttr("msg", msg);
	//			init();
	//			return;
	//		}
	//
	//	}
}